<?php
class Payment{
    private $db=null;
	private $config_site=null;	
    
	function __construct(){
		$this->db=Zend_Registry::get('db');	
		$this->config_site=Zend_Registry::get('config_site');
	}
	
	function __destruct(){
		unset($this->db);
        unset($this->config_site);
	}
    function insert ($data){
        $data['created_time'] = $data['orderdate']; 
        $data['updated_time'] = $data['orderdate'];
        $id = $this->isOrderSeekerExists ($data['motor_id']);
       
        if ($id){
            $ret = $this->db->update('payment', array('status'=>0),'id='.$id);
            return $ret;
        }
            
            
        $ret = $this->db->insert('payment', $data);
        
        if ($ret)
            return $this->db->lastInsertId( 'payment' );
        return 0;             
    }
    
    function isOrderSeekerExists ($motor_id){
        $query = "SELECT id FROM payment WHERE motor_id=".$motor_id;
        return $this->db->fetchOne($query);
    }
}
?>